<script>
  window.onmessage = (event) => {
    if (event.source === window && event.data === 'main-world-port') {
      // message is from preload
      const [ port ] = event.ports
      // once we have the port, we can communicate directly with the main process
      port.onmessage = (event) => {
        console.info('from main process: ', event.data)
        document.writeln(`<p>Received message from main process: ${JSON.stringify(event.data)}</p>`)
        port.postMessage(event.data.test * 2)
      }
    }
  }
</script>